package com.woniu.dating.controller;

import com.woniu.common.annotation.LoginDating;
import com.woniu.common.entity.Result;
import com.woniu.common.entity.ResultCode;
import com.woniu.dating.pojo.DatingConcern;
import com.woniu.dating.service.IDatingConcernService;
import com.woniu.dating.vo.ConcernVO;
import com.woniu.dating.vo.DatingLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 玖柒
 * @since 2023-05-20
 */
@RestController
@RequestMapping("/datingConcern")
@Api(tags = "关注管理")
public class DatingConcernController {

    @Resource
    private IDatingConcernService datingConcernService;


    /**
     * 展示关注列表
     */
    @ApiOperation("展示关注列表")
    @GetMapping("/concern")
    public Result<List<ConcernVO>> watchlist(@LoginDating DatingLoginVO datingLoginVO) {
        //1.查询当前用户下，所有关注人的部分信息
        List<ConcernVO> listConcern = datingConcernService.watchlist(datingLoginVO);
        return Result.ok(listConcern);
    }

    /**
     * 查看用户关注信息，避免重复点赞
     */
    @ApiOperation("判断是否重复关注")
    @GetMapping("/repeat/{userId}")
    public Result repeatConcern(@LoginDating DatingLoginVO datingLoginVO, @PathVariable Integer userId) {
        //1.用当前用户id去查，有则不能关注
        DatingConcern datingConcern = datingConcernService.getDatingConcern(datingLoginVO,userId);
        if (datingConcern == null) {
            return Result.ok(ResultCode.SUCCESS);
        }
        return Result.error(ResultCode.DATING_CONCERN_EXISTED);
    }

    /**
     * 取消关注
     */
    @ApiOperation("取消关注")
    @GetMapping("/cancel/{userId}")
    public Result cancelConcern(@LoginDating DatingLoginVO datingLoginVO, @PathVariable Integer userId) {
        datingConcernService.cancelConcern(datingLoginVO,userId);
        return Result.ok();
    }

    /**
     * 新增关注
     */
    @ApiOperation("点击关注")
    @GetMapping("/add")
    public Result addConcern(@LoginDating DatingLoginVO datingLoginVO, @PathVariable Integer userId) {
        datingConcernService.addConcern(datingLoginVO,userId);
        return Result.ok();
    }

}
